﻿namespace STT
{
    using NativeWin32;
    using STT.Debug;
    using STT.Properties;
    using System;
    using System.IO;
    using System.Runtime.InteropServices;
    using System.Windows.Forms;

    public static class Program
    {
        public static InterGraph Fenetre;
        public static DbgService dbg_service;
        public static string Application_Name = "调试符号查看";
        public static string Application_Url = "http://www.xxxxx.com";
        public static string Applcation_Author = "Lionel d'Hauenens";
        public static string help_symboltypeviewer_path = (new FileInfo(Application.ExecutablePath).DirectoryName + @"\Help_SymbolTypeViewer.rtf");
        public static string aide_symboltypeviewer_path = (new FileInfo(Application.ExecutablePath).DirectoryName + @"\Aide_SymbolTypeViewer.rtf");

        public static string CreateUniqueName()
        {
            DateTime now = DateTime.Now;
            string[] strArray = new string[] { "__", now.Year.ToString("D4"), now.Month.ToString("D2"), now.Day.ToString("D2"), now.Hour.ToString("X2"), now.Minute.ToString("X2"), now.Second.ToString("X2"), now.Millisecond.ToString("X4"), now.Ticks.ToString("X4") };
            string str = string.Concat(strArray);
            while (true)
            {
                DateTime time2 = DateTime.Now;
                if (now.Ticks != time2.Ticks)
                {
                    return str;
                }
            }
        }

        [STAThread]
        private static void Main()
        {
            string path = new FileInfo(Application.ExecutablePath).DirectoryName + @"\dbghelp.dll";
            string str2 = new FileInfo(Application.ExecutablePath).DirectoryName + @"\symsrv.dll";
            IntPtr structure = new IntPtr();
            if (Marshal.SizeOf(structure) == 8)
            {
                if (!File.Exists(path))
                {
                    File.WriteAllBytes(path, Resources.dbghelp_64bit_dll);
                }
                if (!File.Exists(str2))
                {
                    File.WriteAllBytes(str2, Resources.symsrv_64bit_dll);
                }
            }
            else
            {
                if (!File.Exists(path))
                {
                    File.WriteAllBytes(path, Resources.dbghelp_32bit_dll);
                }
                if (!File.Exists(str2))
                {
                    File.WriteAllBytes(str2, Resources.symsrv_32bit_dll);
                }
            }
            File.WriteAllBytes(help_symboltypeviewer_path, Resources.Help_SymbolTypeViewer_rtf);
            File.WriteAllBytes(aide_symboltypeviewer_path, Resources.Aide_SymbolTypeViewer_rtf);
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            dbg_service = new DbgService();
            Fenetre = new InterGraph();
            Application.Run(Fenetre);
            Fenetre = null;
            GC.Collect();
            GC.WaitForPendingFinalizers();
            dbg_service.Dispose();
            dbg_service = null;
            Kernel32Api.FreeLibrary(Kernel32Api.GetModuleHandleA(path));
            Kernel32Api.FreeLibrary(Kernel32Api.GetModuleHandleA(str2));
            try
            {
                File.Delete(path);
                File.Delete(str2);
            }
            catch (Exception)
            {
            }
        }
    }
}